<?php
import('admin.Action.AdmAction');
class AdminAction extends AdmAction {
	
	function index(){
		$spacelist = D('Space','home')->findpage(100);
		$this->assign('spacelist',$spacelist);
		$this->display();
	}
	
	function edit(){
		if($_POST['uid']){
			$a = D('Space','home')->save_Base_Data(intval($_POST['uid']),'baseinfo',$_POST['data'],$_POST['index']);
			
			$user = getUserName($_POST['uid']);			
			D('Log', 'admin')->addLog($this->mid, array('user'=>$user), 'space');
			
			redirect(U('space/Admin/edit/','uid='.$_POST['uid']));
		}else{
			$intId = intval($_GET['uid']);
			$info = D('Space','home')->where('uid='.$intId)->find();
			if($info && $intId){
				$list = D('Space','home')->get_Base_Data($intId,'baseinfo');
				$this->assign('list',$list);
				$this->assign('space',D('Space','home')->get_Space_field($intId,'baseinfo'));
				$this->assign('isHrbi',D('BaseInfo','home')->get_Hrbi_info($info['cardId']));
				$this->assign('cardId',$info['cardId']);
				$this->display();
			}else{
				$this->error('提交错误参数');
			}
		}
	}
	
	//激活空间
	function initSpace(){
		//
		exit;
	   //M()->query("DELETE FROM ts_space WHERE uid in(  SELECT uid FROM `ts_user` WHERE uid > 8000 AND sex is null )");
	  // M()->query("DELETE FROM ts_space_info WHERE uid in(  SELECT uid FROM `ts_user` WHERE uid > 8000 AND sex is null )");
		
	  // $userList = M('user')->where('uid > 8000 AND sex is null')->field('uid,uname')->findall();
	   $pBaseInfo = D('BaseInfo','home');
	   foreach( $userList as $userInfo ){
		   if( $pBaseInfo->get_Hrbi_info($userInfo['uname']) ){	    
		   		$count['all']++;
				$list = $pBaseInfo ->get_Hrbi_Info_Data($userInfo['uname'],'baseinfo');
				foreach($list as $key=>$value){
					$data[$key] = $value['value'];
				}
	
				$a = $pBaseInfo->init_Base_Info($userInfo['uid'],$userInfo['uname'],$data);
				if($a){
					$count['success']++;
					echo $userInfo['uname'].'空间激活成功<br>';
				}else{
					$count['error']++;
					echo $userInfo['uname'].'<font color="blue">空间激活失败</font><br>';
				}
		   }else{
		   		echo $userInfo['uname'].'无Hrbi信息<br>';
		   }
		}
		
		echo '共有 '.intval($count['all']).'人需激活。其中成功激活'.intval($count['success']).'人。失败 '.intval($count['error']).'人';
	}
}
?>